package com.zxy.express.controller;

import com.autopai.base.common.web.constant.Constant;
import com.autopai.base.common.web.model.RestResult;
import com.autopai.base.common.web.page.PageData;
import com.autopai.base.common.web.validator.ValidatorUtils;
import com.autopai.base.common.web.validator.group.AddGroup;
import com.autopai.base.common.web.validator.group.DefaultGroup;
import com.autopai.base.common.web.validator.group.UpdateGroup;
import com.zxy.express.dto.AudioCollectionDTO;
import com.zxy.express.dto.AudioEpisodeDTO;
import com.zxy.express.service.AudioCollectionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.Map;


/**
 * 合集
 *
 * @author zhangxiying ${email}
 * @since ${version} 2025-07-01
 */
@RestController
@RequestMapping("collection")
@Api(tags="合集")
public class AudioCollectionController {
    @Autowired
    private AudioCollectionService audioCollectionService;

    @GetMapping("page")
    @ApiOperation("分页")
    @ApiImplicitParams({
        @ApiImplicitParam(name = Constant.PAGE, value = "当前页码，从1开始", paramType = "query", required = true, dataType="int") ,
        @ApiImplicitParam(name = Constant.LIMIT, value = "每页显示记录数", paramType = "query",required = true, dataType="int")
    })
    public RestResult<PageData<AudioCollectionDTO>> page(@ApiIgnore @RequestParam Map<String, Object> params){
        PageData<AudioCollectionDTO> page = audioCollectionService.page(params);

        return new RestResult<PageData<AudioCollectionDTO>>().ok(page);
    }

    @GetMapping("getById")
    @ApiOperation("信息")
    public RestResult<AudioCollectionDTO> get(@RequestParam String id){
        AudioCollectionDTO data = audioCollectionService.get(id);

        return new RestResult<AudioCollectionDTO>().ok(data);
    }

//    @GetMapping("getByCollectionId")
//    @ApiOperation("根据专辑id获取分集")
//    public RestResult<List<AudioCollectionDTO>> getByCollectionId(@RequestParam String collectionId){
//        AudioCollectionDTO data = audioCollectionService.get(id);
//
//        return new RestResult<AudioCollectionDTO>().ok(data);
//    }

    @PostMapping
    @ApiOperation("保存")
    public RestResult save(@RequestBody AudioCollectionDTO dto){
        //效验数据
        ValidatorUtils.validateEntity(dto, AddGroup.class, DefaultGroup.class);

        audioCollectionService.save(dto);

        return new RestResult();
    }

    @PutMapping
    @ApiOperation("修改")
    public RestResult update(@RequestBody AudioCollectionDTO dto){
        //效验数据
        ValidatorUtils.validateEntity(dto, UpdateGroup.class, DefaultGroup.class);

        audioCollectionService.update(dto);

        return new RestResult();
    }

    @DeleteMapping
    @ApiOperation("删除")
    public RestResult delete(@RequestBody String[] ids){
        //效验数据
       // AssertUtils.isArrayEmpty(ids, "id");

        audioCollectionService.delete(ids);

        return new RestResult();
    }

}